import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:my_meeting/extension/widget_ext.dart';
import 'package:my_meeting/ui/metting/meeting_edit/meeting_edit_logic.dart';
import 'package:my_meeting/widget/confirm_widget.dart';

import '../../../generated/assets.dart';
import '../../../generated/l10n.dart';
import '../../../utils/utils.dart';
import '../../../widget/dialog/dialog_input.dart';
import '../meet_device_time.dart';

class Meeting_editPage extends GetView<Meeting_editLogic> {
  const Meeting_editPage({Key? key}) : super(key: key);

  Widget colorSpace() {
    return Container(
      color: const Color(0xFFF8FAFB),
      height: 6.h,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text(
          S.current.meetingInfo,
          style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w600),
        ),
      ),
      body: Container(
        color: Colors.white,
        padding: EdgeInsets.only(bottom: 15.h),
        child: ListView(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  S.current.meetingOrder,
                  style: TextStyle(
                      fontSize: 16.sp,
                      fontWeight: FontWeight.w500,
                      color: const Color(0xFF666666)),
                ).marginOnly(top: 30.h),
                Divider(
                  height: 1,
                  color: Colors.black.withOpacity(0.08),
                ).marginOnly(top: 10.h),

                //会议内容
                Container(
                  height: 104.h,
                  decoration: BoxDecoration(
                      color: const Color(0xFFE7EFFD),
                      borderRadius: BorderRadius.circular(8.r)),
                  margin: EdgeInsets.only(top: 10.h),
                  child: TextField(
                    controller: controller.textEditController,
                    maxLines: null,
                    onChanged: (text) {
                      controller.meetingData.value.meetingContent = text;
                    },
                    style: TextStyle(
                        color: const Color(0xFF333333),
                        fontSize: 12.sp,
                        fontWeight: FontWeight.w500,
                        height: 1.83),
                    cursorColor: const Color(0xFF1877FF),
                    decoration: InputDecoration(
                      hintText: S.current.meetingContentAdd,
                      hintStyle: TextStyle(
                          color: const Color(0xFF666666),
                          fontSize: 12.sp,
                          fontWeight: FontWeight.w400),
                      border: InputBorder.none,
                    ),
                  ).paddingOnly(left: 10.w),
                ),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          constraints: BoxConstraints(minWidth: 80.w),
                          child: Obx(() {
                            return Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  Utils.getMeetingTime(
                                      controller.meetingData.value
                                          .meetingBeginTime),
                                  style: TextStyle(
                                      color: const Color(0xff333333),
                                      fontSize: 16.sp,
                                      fontWeight: FontWeight.w700),
                                ),
                                Text(
                                  Utils.getMeetingDate(
                                      controller.meetingData.value
                                          .meetingBeginTime),
                                  style: TextStyle(
                                      color:
                                      const Color.fromRGBO(51, 51, 51, 0.6),
                                      fontSize: 12.sp,
                                      fontWeight: FontWeight.w500),
                                )
                              ],
                            );
                          }),
                        ),
                        SvgPicture.asset(
                          Assets.svgTimeEdit,
                          width: 14,
                          height: 14,
                        ).marginOnly(left: 5.h),
                      ],
                    ).gesture(onTap: () => controller.toAppointment()),
                    Expanded(
                      child: Row(
                        children: [
                          Expanded(
                            child: Divider(
                              color: const Color.fromRGBO(0, 0, 0, 0.06),
                              endIndent: 5.w,
                              indent: 10.w,
                            ),
                          ),
                          Container(
                            width: 44.w,
                            alignment: Alignment.center,
                            height: 18.h,
                            decoration: BoxDecoration(
                                color: const Color.fromRGBO(51, 51, 51, 0.1),
                                borderRadius: BorderRadius.circular(4.r)),
                            child: Text(
                              '-',
                              style: TextStyle(
                                  color: const Color(0xff333333),
                                  fontSize: 10.sp,
                                  fontWeight: FontWeight.w500),
                            ),
                          ),
                          Expanded(
                            child: Divider(
                              color: const Color.fromRGBO(0, 0, 0, 0.06),
                              endIndent: 10.w,
                              indent: 5.w,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          constraints: BoxConstraints(minWidth: 80.w),
                          child: Obx(() {
                            return Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  Utils.getMeetingTime(
                                      controller.meetingData.value
                                          .meetingEndTime),
                                  style: TextStyle(
                                      color: const Color(0xff333333),
                                      fontSize: 16.sp,
                                      fontWeight: FontWeight.w700),
                                ),
                                Text(
                                  Utils.getMeetingDate(
                                      controller.meetingData.value
                                          .meetingEndTime),
                                  style: TextStyle(
                                      color:
                                      const Color.fromRGBO(51, 51, 51, 0.6),
                                      fontSize: 12.sp,
                                      fontWeight: FontWeight.w500),
                                )
                              ],
                            );
                          }),
                        ),
                        SvgPicture.asset(
                          Assets.svgTimeEdit,
                          width: 14,
                          height: 14,
                        ).marginOnly(top: 5.h),
                      ],
                    ).gesture(onTap: () => controller.toAppointment()),
                  ],
                ).marginOnly(top: 20.h, bottom: 20.h),
              ],
            ).paddingSymmetric(horizontal: 15.w),
            colorSpace(),
            Column(
              children: [
                Row(
                  children: [
                    Text(
                      S.current.meetingName,
                      style: TextStyle(
                          color: const Color(0xFF333333),
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w500),
                    ),
                    Expanded(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Obx(() {
                            return Text(
                              controller.meetingData.value. meetingName ?? '',
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                  color: const Color(0xFF666666),
                                  fontSize: 14.sp,
                                  fontWeight: FontWeight.w400),
                            );
                          }),
                          GestureDetector(
                            onTap: () {
                              Get.dialog(InputDialog(callback: (text) {
                                controller.meetingData.value.meetingName =
                                    text;
                                controller.meetingData.refresh();
                              }));
                            },
                            child: SvgPicture.asset(
                              Assets.svgTimeEdit,
                              width: 14,
                              height: 14,
                            ).marginOnly(left: 5.w),
                          )
                        ],
                      ),
                    )
                  ],
                ),
                Row(
                  children: [
                    Text(
                      S.current.meetingRoom,
                      style: TextStyle(
                          color: const Color(0xFF333333),
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w500),
                    ),
                    Expanded(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Obx(() {
                            return Text(
                              controller.meetingData.value.meetingAddress ?? '',
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                  color: const Color(0xFF666666),
                                  fontSize: 14.sp,
                                  fontWeight: FontWeight.w400),
                            );
                          }),
                          GestureDetector(
                            onTap: () {
                              Get.dialog(InputDialog(callback: (text) {
                                controller.meetingData.value.meetingAddress =
                                    text;
                                controller.meetingData.refresh();
                              }));
                            },
                            child: SvgPicture.asset(
                              Assets.svgTimeEdit,
                              width: 14,
                              height: 14,
                            ).marginOnly(left: 5.w),
                          )
                        ],
                      ),
                    )
                  ],
                ).marginOnly(top: 20.h),
                Row(
                  children: [
                    Text(
                      S.current.meetingPerson,
                      style: TextStyle(
                          color: const Color(0xFF333333),
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w500),
                    ),
                  ],
                ).marginOnly(top: 20.h),
                SizedBox(
                  width: double.infinity,
                  child: Obx(() {
                    return Wrap(
                      spacing: 8.0, // 控件之间的水平间距
                      runSpacing: 4.0, // 行之间的垂直间距
                      children:
                      List.generate(controller.personArr.length, (index) {
                        String label = controller.personArr[index];
                        return label == '%+%'
                            ? InkWell(
                          onTap: () {
                            Get.dialog(InputDialog(
                              callback: (text) {
                                controller.personArr.insert(
                                    controller.personArr.length - 1,
                                    text);
                                //更新参与人
                                controller.getTakeInPerson();
                              },
                            ));
                          },
                          child: SvgPicture.asset(
                            Assets.svgPersonAdd,
                            width: 28.h,
                            height: 28.h,
                          ),
                        )
                            : personLabelWithTitle(label);
                      }),
                    );
                  }).marginOnly(top: 10.h),
                )
              ],
            ).paddingSymmetric(vertical: 20.h, horizontal: 15.w),
            colorSpace(),
            GestureDetector(
              onTap: () {
                Get.dialog(
                    MeetDeviceTime(
                      title: controller.meetingData.value.deviceOpen,
                      callback: (text) {
                        controller.meetingData.value.deviceOpen = text;
                        controller.meetingData.refresh();
                      },
                    ),
                    barrierDismissible: true);
              },
              child: Container(
                color: Colors.white,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      S.current.meetingDeviceOpen,
                      style: TextStyle(
                          color: const Color(0xFF333333),
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w500),
                    ),
                    Row(
                      children: [
                        Obx(() {
                          return Text(
                            controller.meetingData.value.deviceOpen ?? '-',
                            style: TextStyle(
                                color: const Color(0xFF666666),
                                fontSize: 14.sp,
                                fontWeight: FontWeight.w400),
                          );
                        }),
                        SvgPicture.asset(
                          Assets.svgArrowRight,
                          width: 14,
                          height: 14,
                          color: const Color(0xFF333333),
                        )
                      ],
                    ),
                  ],
                )
                    .marginSymmetric(horizontal: 15.w)
                    .paddingOnly(top: 20.h, bottom: 20.h),
              ),
            ),
            ConfirmWidget(callback: () {
              controller.confirmAction();
            }).marginOnly(left: 15.w, right: 15.w, top: 60.h)
          ],
        ),
      ),
    );
  }

  //参会人标签
  Widget personLabelWithTitle(String title) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 5.h),
      decoration: BoxDecoration(
        color: const Color(0xFF1877FF).withOpacity(0.1),
        borderRadius: BorderRadius.circular(6.r),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            title,
            style: TextStyle(
                color: const Color(0xFF1877FF),
                fontSize: 14.sp,
                fontWeight: FontWeight.w400),
          ),
          InkWell(
            onTap: () {
              controller.personArr.remove(title);
              //更新参与人
              controller.getTakeInPerson();
            },
            child: SvgPicture.asset(
              Assets.svgDeleteIcon,
              width: 14,
              height: 14,
            ).paddingOnly(left: 5.w),
          )
        ],
      ),
    );
  }
}
